<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../css/oksub.css" media="all" />
		<script type="text/javascript" src="../../lib/layui/layui.js"></script>
		<script type="text/javascript" src="../../js/jquery.min.js"></script>
		<script type="text/javascript" src="../../js/service.js"></script>
	</head>

	<body>
		<form class="layui-form" action="">
			<input type="text" name="id" id="id" disabled="disabled" class="layui-input layui-disabled" style="display: none;">
			<div class="layui-form-item">
				<label class="layui-form-label" id="objectName"></label>
				<div class="layui-input-block">
					<input type="text" name="name" id="name" disabled="disabled" class="layui-input layui-disabled">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">开始时间</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="beginTime" name="beginTime">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">消耗时间</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="spendTime" name="spendTime" lay-verify="number" style="display: inline-block !important;width: 70% !important;"><span>小时</span>
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<textarea name="note" placeholder="请输入内容" class="layui-textarea"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>
	<script>
		layui.use(["element", "layer", "table", "form", "laydate"], function() {
			var $ = layui.jquery;
			var layer = layui.layer;
			var form = layui.form;
			var laydate = layui.laydate;

			var sessionStorage = window.sessionStorage;
			var userId = sessionStorage.getItem("userId");
			var userName = sessionStorage.getItem("userName");
			var url = "";

			function getQueryString(name) {
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
				var r = decodeURI(window.location.href).split("?")[1];
				r = r.match(reg);
				if(r != null) {
					return unescape(r[2]);
				}    
				return null;
			};

			var ObjectId = getQueryString("id");
			var ObjectName = getQueryString("name");
			var ObjectType = getQueryString("objType");

			laydate.render({
				elem: '#beginTime' //指定元素
				,type: 'datetime'
				,value: new Date()
			});
			switch(ObjectType) {
				case "任务":
					$("#objectName").html("任务名称:");
					url = "/task/update";
					break;
				case "BUG":
					$("#objectName").html("Bug名称:");
					url = "/bug/update";
					break;
				case "需求":
					$("#objectName").html("需求名称:");
					url = "/demand/update";
					break;
			}
			$("#id").val(ObjectId);
			$("#name").val(ObjectName);
			getdata("/user/search", {}, "GET", function(data) {
				console.log(data);
				data = data.data;
				$.each(data, function(index, item) {
					$("#nameList").append(new Option(item.name, item.id));
				});
				form.render();
			})

			form.on('submit(formDemo)', function(data) {
				console.log(data.field);
				var params = data.field;
				params["loginUserName"] = userName;
				params["loginUserId"] = userId;
				params["state"] = 2;
				getdata(url, params, "POST", function(data) {
					if(data.success){
						layer.msg("启动成功！", {
									icon: 1
								},function(){
  							//do something
  							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //再执行关闭 
							parent.location.reload();
						});
					}else{
						layer.msg(data.msg);
					}
				})

				return false;
			});

		})
	</script>

</html>